package el_Listener;

import java.util.ArrayList;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import el_Bean.GradeInfo;
import el_Bean.User;

//import el_Bean.*;

/**
 * Application Lifecycle Listener implementation class MyListener
 *
 */
@WebListener
public class MyListener implements ServletContextListener, HttpSessionListener {

    /**
     * Default constructor. 
     */
    public MyListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent se)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent se)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce)  { 
         // TODO Auto-generated method stub
    	
    	User zhang=new User();
    	zhang.setName("张三");
    	zhang.setAge(20);
    	ArrayList<String> hobby=new ArrayList<String>();
    	hobby.add("唱歌");
    	hobby.add("跳舞");
    	zhang.setHobby(hobby);
    	
    	GradeInfo gi1=new GradeInfo();
    	gi1.setName("语文");
    	gi1.setGrade(80);
    	GradeInfo gi2=new GradeInfo();
    	gi2.setName("数学");
    	gi2.setGrade(90);
    	
    	ArrayList<GradeInfo> grade=new ArrayList<GradeInfo>();
    	grade.add(gi1);
    	grade.add(gi2);
    	
    	zhang.setGrade(grade);
    	
//-------------------------------------------
    	
    	User li=new User();
    	li.setName("李四");
    	li.setAge(21);
    	ArrayList<String> hobby1=new ArrayList<String>();
    	hobby1.add("游泳");
    	hobby1.add("旅游");
    	li.setHobby(hobby1);
    	
    	GradeInfo gi3=new GradeInfo();
    	gi3.setName("语文");
    	gi3.setGrade(95);
    	GradeInfo gi4=new GradeInfo();
    	gi4.setName("数学");
    	gi4.setGrade(99);
    	
    	ArrayList<GradeInfo> grade2=new ArrayList<GradeInfo>();
    	grade2.add(gi3);
    	grade2.add(gi4);
    	
    	li.setGrade(grade2);
    	
    //聚集所有学生的信息
    	ArrayList<User> all=new ArrayList<User>();
    	all.add(zhang);
    	all.add(li);
    	sce.getServletContext().setAttribute("USER",all);
    }
	
}
